window.onload = function () {
    $("#submit-btn").click(function (event) {
        event.preventDefault();
        let title = $("input[name='title']").val();
        let category = $("#category-select").val();
        let content = $("#content").val();
        let csrfmiddlewaretoken = $("input[name='csrfmiddlewaretoken']").val();
        $.ajax('blog_pub', {
            method: 'POST', data: {
                title, category, content, csrfmiddlewaretoken
            },
            success: function (result) {
                if (result['code'] == 200) {
                    let blog_id = result['data']['blog_id']
                    window.location = 'blog_detail/'+ blog_id;
                } else {
                    alert(result['message']);
                }
            }
        });
    })
}